import { director, ITweenOption } from "cc";
import { LayerCatAction } from "./LayerCatAction";
import { LayerRootAction } from "./LayerRootAction";
import { LayerEmptyAction } from "./LayerEmptyAction";
import { Main } from "./Main";
import { ShowLevelAction } from "./ShowLevelAction";
import { GameOverAction } from "./GameOverAction";
import { CoinsAction } from "./CoinsAction";
import { SuccessAction } from "./SuccessAction";
import { LayerBtnAction } from "./LayerBtnAction";
import { TipsAction } from "./TipsAction";
import { BucketAction } from "./BucketAction";
import { PropsAction } from "./PropsAction";
import { GuideAction } from "./GuideAction";
import { Key } from "./Enums";

export class Global {

    static start = false;
    static loading_rate = 0;
    //token
    static token: string;
    static userInfo: any;

    // 各功能模块实例
    static layer_cat_action: LayerCatAction;
    static layer_root_action: LayerRootAction;
    static layer_empty_action: LayerEmptyAction;
    static main_action: Main;
    static Show_level_action: ShowLevelAction; // 添加默认实例

    static game_over_action: GameOverAction;
    static coins_action: CoinsAction;
    static success_action: SuccessAction;
    static layer_btn_action: LayerBtnAction;
    static tips_action: TipsAction;
    static bucket_action: BucketAction;
    static props_action: PropsAction;

    static guide_action: GuideAction;

    // 游戏暂停状态控制
    static Pause(isPause = true) {
        director.emit(Key.Pause, isPause);
        Global.start = !isPause;
    }

    // 当前关卡钉子总数和已移动数
    static cur_lvl_pin_total = 0;
    static cur_lvl_pin_move_num = 0;

    public static init_pin_info(total: number) {
        Global.cur_lvl_pin_total = total;
        Global.cur_lvl_pin_move_num = 0;
    }

    public static pin_prgress_computed(num: number) {
        Global.cur_lvl_pin_move_num += num;
    }

    // 当前关卡
    public static cur_lvl = 1;

    public static next_level(): number {
        Global.cur_lvl++;
        return Global.cur_lvl;
    }

    // 音效开关
    static sound_switch = true;

    // 当前金币数
    static cur_coins = 0;

    // 使用道具需要的基础金币数（关卡会乘以这个）
    static need_coins = 30;

    public static get_need_coins(): number {
        return Global.need_coins * Global.cur_lvl;
    }

    // 使用硬币
    public static use_coins(c: number) {
        // 将当前硬币数量减去传入的硬币数量，取最大值为0
        Global.cur_coins = Math.max(Global.cur_coins - c, 0);
    }

    // 游戏从头开始，默认重置等级和金币
    public static restart_default(lvl = 0) {
        Global.cur_lvl = lvl;
        Global.cur_coins = 0;
    }

    // 每关开始时的默认处理
    public static every_level_default() {
        Global.cur_lvl_pin_total = 0;
        Global.cur_lvl_pin_move_num = 0;

        // 清理桶内钉子容器
        Global.bucket_action.clear_container();

        Global.guide_action.action_lvl_start_begin();
    }

    // 动画缓动效果参数
    static our_easing: ITweenOption = { easing: 'quadInOut' };

    // 广告ID
    static ad_intersitial_id: string;
    static ad_video_id: string;
    static ad_banner_id: string;

    // 是否检查完成关卡
    static is_check_completed = false;
}
